/*
 * TCSS 422 Process Control Simulator
 * Group Money: Al McKenzie, Michael Pitts, Taylor Zielske
 */

/**
 * A Process that writes (produces) shared data.
 * @author Michael Pitts
 * @version Dec 1, 2011
 */
public class Producer extends AbstractSharedProcess {

	/**
	 * Creates a new Producer, which writes the Shared data.
	 * @param the_name is the name of the new Producer.
	 * @param the_limit is the number of iterations the Producer should run.  If
	 * negative or zero will run forever.
	 * @param the_shared is the shared data to write on.
	 */
	public Producer(final String the_name, final int the_limit, 
			final Shared the_shared) {
		super(the_name, the_limit, the_shared);
	}

	@Override SysCall work() {
		Main.out().println(toString() + " writing to Shared memory.");
		return SysCall.MEM_WRITE;
	}

	@Override boolean checkData() {
		return my_shared.memory_read() == 0;
	}

	@Override void done() {
		Main.out().println("Done producing Shared data.");
		my_shared.memory_write(1);
	}
}
